/**
 * 
 */
package v1c09;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 * @author gjunming@gmail.com
 * @version Aug 10, 2009 3:37:53 PM
 */
public class FormTest {

	protected static final int FHEIGHT = 200;
	protected static final int FWIDTH = 300;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {

			@Override
			public void run() {
				FormFrame formFrame = new FormFrame();
				formFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				formFrame.setVisible(true);
				formFrame.setSize(FWIDTH, FHEIGHT);
			}
		});

	}

}

class FormFrame extends JFrame {
	private static final long serialVersionUID = 1L;

	public FormFrame() {

		JPanel formPanel = new JPanel();
		formPanel.setLayout(new BorderLayout());
		add(formPanel);

		JPanel inputPanel = new JPanel();
		inputPanel.setLayout(new GridLayout(2, 2));

		inputPanel.add(new JLabel("User Name;"));
		final JTextField textUsername = new JTextField();
		inputPanel.add(textUsername);
		inputPanel.add(new JLabel("Password:"));
		final JPasswordField textPassword = new JPasswordField();
		inputPanel.add(textPassword);

		formPanel.add(inputPanel, BorderLayout.NORTH);
		// end input panel;

		final JTextArea textShow = new JTextArea(8, 40);
		formPanel.add(textShow, BorderLayout.CENTER);
		// end showing area;

		JButton doshow = new JButton("insert");

		doshow.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				textShow.append("Username: " + textUsername.getText()
						+ "---Password: "
						+ new String(textPassword.getPassword())
						+ "\n");
			}
		});

		formPanel.add(doshow, BorderLayout.SOUTH);
	}
}
